
"""
需结合上下文分析的问题点
"""

from models import Chapter
from pydantic import Field
from core.utils import BaseAnalyzer, prompt_dir
from typing import List


class ProblemsAnalyzer(BaseAnalyzer):

    def __init__(self):
        super().__init__(prompt_file=prompt_dir / 'context/c5. 问题点分析.md')

    def invoke(
            self,
            last_chapter: Chapter = Field(description='上一章节'),
            archived_characters: List = Field(description="人物的历史信息"),
            current_chapter: Chapter = Field(description="当前章节内容")
    ):
        prompt = self.template_prompt.format(
            inputs={
                "plot": last_chapter.plot,
                "archived_characters": '\n'.join([str(character) for character in archived_characters]),
                "established_worldview": last_chapter.worldview,
                "chapter_content": current_chapter.chapter_content
            },
            remove_template_variables=True
        )
        current_chapter.problems = self.analyze(prompt)
        return current_chapter.problems
